package com.ee.chat.api;

import com.alibaba.fastjson.JSON;
import com.ee.chat.common.dao.SysSensitiveWordLibMapper;
import com.ee.chat.common.service.IGeneralService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@SpringBootApplication(scanBasePackages = "com.ee.chat")
public class ChatApiApplication {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Resource
    IGeneralService generalService;
    @Resource
    SysSensitiveWordLibMapper sysSensitiveWordLibMapper;
    @Resource(name = "stringRedisTemplate")
    StringRedisTemplate redisTemplate;

    public static void main(String[] args) {
        SpringApplication.run(ChatApiApplication.class, args);
    }

    /**
     * 缓存城市数据
     * @Author Shane
     * @Date 2019/10/11 0:33
     * @param
     * @return
     */
//    @PostConstruct
    public void toLoadCityLib(){
        Date time1 = new Date();
        List<Map<String, Object>> areaLibToCity = generalService.getAreaLibToCity();
        String json = JSON.toJSONString(areaLibToCity);
        redisTemplate.opsForHash().put("data", "areaLibToCity", json);
        Date time2 = new Date();
        log.info("缓存城市数据成功，耗时："+((time2.getTime() - time1.getTime()) / 1000) +"秒");
    }

    /**
     * 缓存敏感词数据
     * @Author Shane
     * @Date 2019/10/11 0:33
     * @param
     * @return
     */
    /*@PostConstruct
    public void toLoadSensitiveWordLib() throws Exception{
        Date time1 = new Date();
        List<String> words = sysSensitiveWordLibMapper.getWords();
        String[] wordArr = new String[words.size()];
        redisTemplate.opsForSet().add("data:sensitiveWord", words.toArray(wordArr));
        Date time2 = new Date();
        log.info("缓存敏感词数据成功，耗时："+((time2.getTime() - time1.getTime()) / 1000) +"秒");
    }*/
}
